import Vue from 'vue'
export default {
	namespaced: true,
	state: () => ({

		addressList: [{
			name: "",
			address: "",
			contact: "",
			phone: "",
			addressType: 0,
			lat: "",
			lng: "",
			detail: "",
			addsort: ''
		}, {
			name: "",
			address: "",
			contact: "",
			phone: "",
			addressType: 1,
			lat: "",
			lng: "",
			detail: "",
			addsort: ''
		}], //地址详情
		
		addressMod: [{
			name: "",
			address: "",
			contact: "",
			phone: "",
			addressType: 0,
			lat: "",
			lng: "",
			detail: "",
			addsort: ''
		}, {
			name: "",
			address: "",
			contact: "",
			phone: "",
			addressType: 1,
			lat: "",
			lng: "",
			detail: "",
			addsort: ''
		}], //地址详情
		
		
		order: {
			shipperOrderDetailDto: {
				appointDrivers: '', //收藏司机
				ownerUnitPrice: '', //货主单价
				transUnitPrice: '', //供应商运输单价
				pricingMethod: '1', //计价方式
				measureUnit: '', //计量单位
				startAmount: '', //起步价
				isWhole: "", //是否整车运输
				totalAmount: "", //总金额
				useCarType: "2", //用车（1企业2个人）
				paymentType: "", //付款类型
				carTypeNeeds: {
					need: '',
					mode: '',
					name:'',
					carType:''
				}, //车辆类型
				followPerson: "", //跟车人数量
				totalDistant: "", //总路程
				distantAmount: "", //订单里程金额（不含其他费用）
				insuranceAmount: "5", //保险费用
				gratuityAmount: "", //小费
				tags: "", //标签（需要推车,有易碎物品等）
				moveHouse:false, //是否为搬家true/false
				moveHouseValue:'',
				description: "", //下单备注
				receiptType: "0", //回单服务
				invoiceType: "0", //开票类型
				reservation: "", //用车类型（0立即用车1预约用车）
				shipmentTime: "", //预约装货时间
				unloadTime: "" //预约卸货时间
			},
			addrlist: [{
				addressType: "", //0发货1卸货
				addsort: "", //1,2,3排序
				name: "", //地址别名
				address: "", //地址
				detail: "", //详细地址
				contact: "", //联系人
				phone: "", //手机号
				lng: "", //经度
				lat: "" //纬度
			}]

		},
		
		
		
		Primitive: {
			shipperOrderDetailDto: {
				appointDrivers: '', //收藏司机
				ownerUnitPrice: '', //货主单价
				transUnitPrice: '', //供应商运输单价
				pricingMethod: '', //计价方式
				measureUnit: '', //计量单位
				startAmount: '', //起步价
				isWhole: "", //是否整车运输
				totalAmount: "", //总金额
				useCarType: "2", //用车（1企业2个人）
				paymentType: "", //付款类型
				carTypeNeeds: {
					need: '燃油',
					mode: '',
					name:'',
					carType:''
				}, //车辆类型
				followPerson: "", //跟车人数量
				totalDistant: "", //总路程
				distantAmount: "", //订单里程金额（不含其他费用）
				insuranceAmount: "5", //保险费用
				gratuityAmount: "", //小费
				tags: "", //标签（需要推车,有易碎物品等）
				moveHouse:false, //是否为搬家true/false
				moveHouseValue:'',
				description: "", //下单备注
				receiptType: "0", //回单服务
				invoiceType: "0", //开票类型
				reservation: "", //用车类型（0立即用车1预约用车）
				shipmentTime: "", //预约装货时间
				unloadTime: "" //预约卸货时间
			},
			addrlist: [{
				addressType: "", //0发货1卸货
				addsort: "", //1,2,3排序
				name: "", //地址别名
				address: "", //地址
				detail: "", //详细地址
				contact: "", //联系人
				phone: "", //手机号
				lng: "", //经度
				lat: "" //纬度
			}]
		
		},
	}),
	mutations: {
		//订单车辆选择
		carOder(state, data) {
			for (let k in data) {
				state.order.shipperOrderDetailDto.carTypeNeeds[k] = data[k]
			}
		},
		//订单地址选择
		addressOder(state, data) {
			state.order.addrlist = data
		},
		//订单类型选择
		changeOder(state, data) {
			for (let k in data) {
				state.order.shipperOrderDetailDto[k] = data[k]
			}
		},
		//回复原始
		Primitive(state,data){
			state.order = state.Primitive
			state.addressList= state.addressMod
			uni.setStorageSync('up',1)
		},







		//修改地址
		setAddressList(state, data) {
			state.addressList = data
			uni.setStorageSync("addressList", JSON.stringify(state.addressList));
		},
		TianjiaAddress(state, data) {

			state.addressList = data
			state.addressList.forEach((item, i) => {
				state.addressList[i].addsort = i + 1
			})
			uni.setStorageSync("addressList", JSON.stringify(state.addressList));
		},
		// 添加地址
		addAddressList(state, data) {
			let cont = []
			cont = state.addressList.pop()
			state.addressList.push(data)
			state.addressList.push(cont)
			state.addressList.forEach((item, i) => {
				state.addressList[i].addsort = i + 1
			})
			console.log(state.addressList)
			uni.setStorageSync("addressList", JSON.stringify(state.addressList));
		},
		// 修改地址某个指定地址
		deleteAddressList(state, {
			index,
			data
		}) {
			for (let k in data) {
				state.addressList[index][k] = data[k]
			}
			uni.setStorageSync("addressList", JSON.stringify(state.addressList));
		},
		//删除地址
		deleteAddress(state, data) {
			state.addressList.forEach((item, i) => {
				if (i == data) {
					state.addressList.splice(i, 1)
				}
			})
			uni.setStorageSync("addressList", JSON.stringify(state.addressList));
		},

		//交换地址
		exchangeAddressList(state, index) {
			let adlist = JSON.parse((JSON.stringify(state.addressList)))
			let da = adlist[index - 1]
			let da2 = adlist[index]
			adlist[index - 1] = da2
			adlist[index] = da
			state.addressList = adlist
			uni.setStorageSync("addressList", JSON.stringify(state.addressList));
		},
		//修改备注


		
	},
	actions: {

	}
}